package cate.game.chat;

import cate.game.role.Role;
import org.apache.commons.lang3.StringUtils;

public class ChatFilter {

    /** 要求发送者和接收者是同省 */
    public boolean provinceSameRequired = false;

    /** 要求发送者和接收者是同一仙盟 */
    public boolean guildSameRequired = false;

    /** 要求发送者和接收者是同一渠道 */
    public boolean gameIdSameRequired = false;

    /** 只发给自己看 */
    public boolean selfRequired = false;

    /** 只发给某个人的idhex */
    public String selfUid;

    public String guildUid;

    public boolean filterBlackList = false;


    /** 没有要求 */
    public boolean none() {
        return !provinceSameRequired
                && !guildSameRequired
                && !gameIdSameRequired
                && !selfRequired
                && !filterBlackList;
    }

    /** 是否可以接收该消息 */
    public boolean accept(ChatPublicItem item, Role role) {
        if (selfRequired) {
            return StringUtils.equals(selfUid, role.getUid());
        }
        if (guildSameRequired) {
            return StringUtils.equals(guildUid, role.getRes().guild.uid);
        }
        if (filterBlackList) {
            return !role.getFriend().inBlackList(item.sender.id);
        }
        return true;
    }
}
